package uml.behavioral.state;

/**
 * 状态--具体状态类<br>
 * on 2023/1/6 0:16
 */
public class RestrictedState extends AccountState {
    private float ration = 0.015f;

    public RestrictedState(Account acc) {
        super(acc);
    }

    public RestrictedState(AccountState state) {
        super(state);
    }

    @Override
    public void withdraw(double amount) {
        System.out.println("账号透支超过2000元，不能再取款");
    }

    @Override
    public void deposit(double amount) {
        acc.setBalance(acc.getBalance() + amount);
        stateCheck();
    }

    @Override
    public void computeInterest() {
        double d = -acc.getBalance();
        if (d <= 2000) {
            System.out.println("账户需支付透支利息(1%):" + -acc.getBalance() * 0.01);
        } else {
            System.out.println("账户需支付透支部分利息(1%):" + 2000 * 0.01);
            System.out.println("账户需支付超额部分利息(1.1%):" + (d - 2000) * 0.01);
        }
    }

    @Override
    public void stateCheck() {
        if (acc.getBalance() > 0) {
            acc.setState(new NormalState(this));
        } else if (acc.getBalance() > -2000) {
            acc.setState(new OverdraftState(this));
        }
    }
}
